package com.hc.kotlin

fun main() {
    var list = listOf("123","456","789")
    list = list.map {//map 遍历每个元素生成
        "${it}!"
    }.map {
        "${it}?"
    }.toMutableList()
    println(list)
    var list2 = listOf(listOf("12","34"), listOf("56","78")).flatMap {//flatMap 组合元素
        it
    }
    println(list2)
    var list3 = listOf("123","456","789")
    list3 = list3.filter {//filter 过滤
        it.contains("78")
    }
    println(list3)
    var ints = listOf(3,5,7,8,9,11)
    ints = ints.filter { n ->
        (2 until n)
        .map {
            (n % it)
        }.none {
            it == 0
        }
    }
    println(ints)
    var list4 = listOf(12,34)
    var list5 = listOf(56,78)
    val zip = list4.zip(list5) //zip 组合生成类似键值对
    println(zip)
    var total = listOf(1,2,3).fold(0){ temp,index-> //fold 累计结果
        temp + index * 2
    }
    println(total)
}